//=============================================================================
/**
 *
 *	@file		course.c
 *	@brief		ポケスロン コースレコード画面
 *	@author		hosaka genya
 *	@data		2008.06.24
 *
 */
//=============================================================================
#include "common.h"
#include "gflib/touchpanel.h"
#include "system/procsys.h"
#include "system/arc_util.h"
#include "system/arc_tool.h"
#include "system/brightness.h"
#include "system/bmp_list.h"
#include "system/bmp_menu.h"
#include "system/window.h"
#include "system/pm_str.h"
#include "system/msgdata.h"
#include "system/wordset.h"
#include "system/fontproc.h"
#include "system/snd_tool.h"
#include "system/clact_util.h"
#include "system/clact_tool.h"
#include "system/render_oam.h"
#include "system/gra_tool.h"
#include "system/palanm.h"
#include "system/wipe.h"
#include "poketool/poke_tool.h"
#include "poketool/pokeicon.h"

#include "msgdata/msg.naix"
#include "msgdata/msg_pokethlon_museum.h"

#include "application/museum.h"

#include "museum_util.h"
#include "museum_obj.h"
#include "museum_bg.h"

#include "system/pm_overlay.h"

#include "pkth_museum.naix"
#include "course_obj_NANR_LBLDEFS.h"
#include "obj_trophy_NANR_LBLDEFS.h"

FS_EXTERN_OVERLAY(pkthln_common);

//=============================================================================
/**
 *								定数定義
 */
//=============================================================================

//-----------------------------------------------------------------------------
// GF_PRINT_COLOR
//-----------------------------------------------------------------------------
// -- 透明色 --
#define COL_NL (GF_PRINTCOLOR_MAKE(0, 0, 0))
// -- 白 --
#define	COL_WW (GF_PRINTCOLOR_MAKE(15, 15, 0))
// -- 黒 --
#define COL_BW (GF_PRINTCOLOR_MAKE(FBMP_COL_BLACK, FBMP_COL_BLK_SDW, FBMP_COL_NULL))

//--------------------------------------------------------------
///	汎用
//==============================================================
enum {
	// -- BG Frame --
	FRM_M_TEXT	= GF_BGL_FRAME0_M,
	FRM_M_BASE	= GF_BGL_FRAME1_M,
	FRM_M_MEDAL	= GF_BGL_FRAME2_M,
	FRM_M_WIN	= GF_BGL_FRAME3_M,

	FRM_S_BASE	= GF_BGL_FRAME0_S,
	FRM_S_MEDAL	= GF_BGL_FRAME1_S,
	FRM_S_TEXT	= GF_BGL_FRAME2_S,
	FRM_S_WIN	= GF_BGL_FRAME3_S,

	// -- BMPWIN 関係 --
	BMPWIN_M_CGX = 1,
	BMPWIN_S_CGX = 1,

	// -- OBJ 関連 --
	POKE_ID_00 = 0,
	POKE_ID_01,
	POKE_ID_02,
	POKE_MAX = 3,
};

// -- BMPWIN IDX --
enum {
	BMPWIN_MODE = 0,
	BMPWIN_MDL_NAME,
	BMPWIN_RETURN,
	BMPWIN_S_CRS_NAME,
	BMPWIN_S_CAP,
	BMPWIN_S_THRON_NAME_01,
	BMPWIN_S_THRON_NAME_02,
	BMPWIN_S_THRON_NAME_03,
	BMPWIN_S_THRON_SCORE_01,
	BMPWIN_S_THRON_SCORE_02,
	BMPWIN_S_THRON_SCORE_03,
	BMPWIN_S_BONUS,
	BMPWIN_S_BONUS_SCORE,
	BMPWIN_S_TOTAL_SCORE_CAP,
	BMPWIN_S_RANK_01,
	BMPWIN_S_RANK_02,
	BMPWIN_S_RANK_03,
	BMPWIN_MAX,
};

//--------------------------------------------------------------
/// 画面に表示するセルタクターの番号定義
//==============================================================
enum {
	//-- Main LCD --
	OBJ_ID_MEDAL_CURSOR = 0,
	OBJ_ID_MEDAL_SPEED,
	OBJ_ID_MEDAL_POWER,
	OBJ_ID_MEDAL_TECHNIC,
	OBJ_ID_MEDAL_STAMINA,
	OBJ_ID_MEDAL_JUMP,
	OBJ_ID_MEDAL_SPEED_EFF,
	OBJ_ID_MEDAL_POWER_EFF,
	OBJ_ID_MEDAL_TECHNIC_EFF,
	OBJ_ID_MEDAL_STAMINA_EFF,
	OBJ_ID_MEDAL_JUMP_EFF,
	OBJ_ID_MEDAL_POKE_0,
	OBJ_ID_MEDAL_POKE_1,
	OBJ_ID_MEDAL_POKE_2,
	OBJ_ID_NUM_0,
	OBJ_ID_NUM_1,
	OBJ_ID_NUM_2,
	OBJ_ID_EFF_0,
	OBJ_ID_EFF_1,
	OBJ_ID_EFF_2,
	//-- Sub LCD --
	OBJ_ID_S_NUM_0,
	OBJ_ID_S_NUM_1,
	OBJ_ID_S_NUM_2,
	// ↓↓↓↓
	// -- poke icon --
	OBJ_ID_S_POKE_0,
	OBJ_ID_S_POKE_1,
	OBJ_ID_S_POKE_2,
	OBJ_ID_MAX,
};


//--------------------------------------------------------------
///	OBJ用：リソースID
//==============================================================
enum {
	CHR_ID_M_COURSE = 0,
	CHR_ID_M_TROPHY,
	CHR_ID_M_MEDAL,
	CHR_ID_M_POKEGRA_0,
	CHR_ID_M_POKEGRA_1,
	CHR_ID_M_POKEGRA_2,
	CHR_ID_S_NUM,
	CHR_ID_S_POKEICON_0,
	CHR_ID_S_POKEICON_1,
	CHR_ID_S_POKEICON_2,
	CHR_ID_MAX,
};

enum {
	PAL_ID_M_COURSE = 0,
	PAL_ID_M_TROPHY,
	PAL_ID_M_MEDAL,
	PAL_ID_S_NUM,
	PAL_ID_M_POKEGRA_0,
	PAL_ID_M_POKEGRA_1,
	PAL_ID_M_POKEGRA_2,
	PAL_ID_S_POKEICON,
	PAL_ID_MAX,
};

enum {
	CEL_ID_COURSE = 0,
	CEL_ID_TROPHY,
	CEL_ID_MEDAL,
	CEL_ID_S_NUM,
	CEL_ID_POKEGRA,
	CEL_ID_POKEICON,
	CEL_ID_MAX,
};

enum {
	ANM_ID_COURSE = 0,
	ANM_ID_TROPHY,
	ANM_ID_MEDAL,
	ANM_ID_S_NUM,
	ANM_ID_POKEGRA,
	ANM_ID_POKEICON,
	ANM_ID_MAX
};


//--------------------------------------------------------------
///	コースID
//==============================================================
typedef enum
{
	COURSE_ID_SPEED = 0,
	COURSE_ID_POWER,
	COURSE_ID_TECHNIC,
	COURSE_ID_STAMINA,
	COURSE_ID_JUMP,
	COURSE_ID_MAX
}COURSE_ID;

//=============================================================================
/**
 *								データテーブル
 */
//=============================================================================

//--------------------------------------------------------------
///	使用するBGのリスト BG_Init, BG_Release から依存関係
//==============================================================
enum{ BG_USE_NUM = 8, };

static const u8 c_BG_UseList[ BG_USE_NUM ] = {
	GF_BGL_FRAME0_M, GF_BGL_FRAME1_M, GF_BGL_FRAME2_M, GF_BGL_FRAME3_M,
	GF_BGL_FRAME0_S, GF_BGL_FRAME1_S, GF_BGL_FRAME2_S, GF_BGL_FRAME3_S
};

//--------------------------------------------------------------
///	メダルOBJの座標
//==============================================================
enum
{
	OBJPOS_MEDAL_SPEED_X	= 26*8,	OBJPOS_MEDAL_SPEED_Y	= 2*8,
	OBJPOS_MEDAL_POWER_X	= 30*8,	OBJPOS_MEDAL_POWER_Y	= 6*8,
	OBJPOS_MEDAL_TOCHNIC_X	= 26*8,	OBJPOS_MEDAL_TOCHNIC_Y	= 10*8,
	OBJPOS_MEDAL_STAMINA_X	= 30*8,	OBJPOS_MEDAL_STAMINA_Y	= 14*8,
	OBJPOS_MEDAL_JUMP_X		= 26*8,	OBJPOS_MEDAL_JUMP_Y		= 18*8,
	POS_EXIT_X				= 28*8,	POS_EXIT_Y				= 22*8,

	OBJPOS_MEDAL_POKE_0_X	= 12*8,	OBJPOS_MEDAL_POKE_0_Y	= 8*8,
	OBJPOS_MEDAL_POKE_1_X	= 7*8,	OBJPOS_MEDAL_POKE_1_Y	= 13*8,
	OBJPOS_MEDAL_POKE_2_X	= 17*8,	OBJPOS_MEDAL_POKE_2_Y	= 13*8,

	OBJPOS_NUM_0_X			= 15*8,	OBJPOS_NUM_0_Y		= 19*8,
	OBJPOS_NUM_1_X			= 13*8,	OBJPOS_NUM_1_Y		= 19*8,
	OBJPOS_NUM_2_X			= 11*8,	OBJPOS_NUM_2_Y		= 19*8,

	OBJPOS_EFF_0_X			= 16*8,	OBJPOS_EFF_0_Y = 7*8,
	OBJPOS_EFF_1_X			= 5*8,	OBJPOS_EFF_1_Y = 12*8,
	OBJPOS_EFF_2_X			= 16*8,	OBJPOS_EFF_2_Y = 19*8,

	OBJPOS_S_NUM_0_X		= 26*8,	OBJPOS_S_NUM_0_Y	= 19*8 - 3,
	OBJPOS_S_NUM_1_X		= 22*8,	OBJPOS_S_NUM_1_Y	= 19*8 - 3,
	OBJPOS_S_NUM_2_X		= 18*8,	OBJPOS_S_NUM_2_Y	= 19*8 - 3,
};

static const s16 c_medal_pos_tbl[][2] =
{
	{ OBJPOS_MEDAL_SPEED_X,		OBJPOS_MEDAL_SPEED_Y },		//< SPEED
	{ OBJPOS_MEDAL_POWER_X,		OBJPOS_MEDAL_POWER_Y },		//< POWER
	{ OBJPOS_MEDAL_TOCHNIC_X,	OBJPOS_MEDAL_TOCHNIC_Y },	///< TECHNIC
	{ OBJPOS_MEDAL_STAMINA_X,	OBJPOS_MEDAL_STAMINA_Y },	///< STAMINA
	{ OBJPOS_MEDAL_JUMP_X,		OBJPOS_MEDAL_JUMP_Y },		///< JUMP
	{ POS_EXIT_X,				POS_EXIT_Y }, ///< EXIT
};

//-----------------------------------------------------------------------------
#define BMP_STRING_H ( 2 )
//-- main
#define BMP_M_MODE_W		( 14 )
#define BMP_M_CRS_NAME_W	( 14 )
#define BMP_M_RETURN_W		( 6 )
//-- main cgx
#define BMP_M_MODE_CGX		( BMPWIN_M_CGX )
#define BMP_M_CRS_NAME_CGX	( BMP_M_MODE_CGX		+ BMP_M_MODE_W		* BMP_STRING_H )
#define BMP_M_RETURN_CGX	( BMP_M_CRS_NAME_CGX	+ BMP_M_CRS_NAME_W	* BMP_STRING_H )
#define BMP_M_CGX_MAX		( BMP_M_RETURN_CGX		+ BMP_M_RETURN_W	* BMP_STRING_H )
//-- sub
#define BMP_S_CRS_NAME_W		( 14 )
#define BMP_S_CAP_W				( 28 )
#define BMP_S_THRON_NAME_01_W	( 14 )
#define BMP_S_THRON_NAME_02_W	( 14 )
#define BMP_S_THRON_NAME_03_W	( 14 )
#define BMP_S_THRON_SCORE_01_W	( 8 )
#define BMP_S_THRON_SCORE_02_W	( 8 )
#define BMP_S_THRON_SCORE_03_W	( 8 )
#define BMP_S_BONUS_W			( 14 )
#define BMP_S_BONUS_SCORE_W		( 8 )
#define BMP_S_TOTAL_SCORE_CAP_W ( 6 )
#define BMP_S_RANK_01_W			( 12 )
#define BMP_S_RANK_02_W			( 12 )
#define BMP_S_RANK_03_W			( 12 )
//-- sub cgx
#define BMP_S_CRS_NAME_CGX			( BMPWIN_S_CGX )
#define BMP_S_CAP_CGX				( BMP_S_CRS_NAME_CGX		+ BMP_S_CRS_NAME_W			* BMP_STRING_H )
#define BMP_S_THRON_NAME_01_CGX		( BMP_S_CAP_CGX				+ BMP_S_CAP_W				* BMP_STRING_H )
#define BMP_S_THRON_NAME_02_CGX		( BMP_S_THRON_NAME_01_CGX	+ BMP_S_THRON_NAME_01_W		* BMP_STRING_H )
#define BMP_S_THRON_NAME_03_CGX		( BMP_S_THRON_NAME_02_CGX	+ BMP_S_THRON_NAME_02_W		* BMP_STRING_H )
#define BMP_S_THRON_SCORE_01_CGX	( BMP_S_THRON_NAME_03_CGX	+ BMP_S_THRON_NAME_03_W		* BMP_STRING_H )
#define BMP_S_THRON_SCORE_02_CGX	( BMP_S_THRON_SCORE_01_CGX	+ BMP_S_THRON_SCORE_01_W	* BMP_STRING_H )
#define BMP_S_THRON_SCORE_03_CGX	( BMP_S_THRON_SCORE_02_CGX	+ BMP_S_THRON_SCORE_02_W	* BMP_STRING_H )
#define BMP_S_BONUS_CGX				( BMP_S_THRON_SCORE_03_CGX	+ BMP_S_THRON_SCORE_03_W	* BMP_STRING_H )
#define BMP_S_BONUS_SCORE_CGX		( BMP_S_BONUS_CGX			+ BMP_S_BONUS_W				* BMP_STRING_H )
#define BMP_S_TOTAL_SCORE_CAP_CGX	( BMP_S_BONUS_SCORE_CGX		+ BMP_S_BONUS_SCORE_W		* BMP_STRING_H )
#define BMP_S_RANK_01_CGX			( BMP_S_TOTAL_SCORE_CAP_CGX	+ BMP_S_TOTAL_SCORE_CAP_W	* BMP_STRING_H )
#define BMP_S_RANK_02_CGX			( BMP_S_RANK_01_CGX			+ BMP_S_RANK_01_W			* BMP_STRING_H )
#define BMP_S_RANK_03_CGX			( BMP_S_RANK_02_CGX			+ BMP_S_RANK_02_W			* BMP_STRING_H )
#define BMP_S_CGX_MAX				( BMP_S_RANK_03_CGX			+ BMP_S_RANK_03_W			* BMP_STRING_H )

//--------------------------------------------------------------
///	BMPWIN用 データテーブル
//==============================================================
static const BMPWIN_DAT c_BmpWinList[ BMPWIN_MAX ] =
{
	// -- main --
	{	// -- BMPWIN_MODE --
		FRM_M_TEXT, 0, 0, BMP_M_MODE_W, 2, FONT_TALK_PAL, BMP_M_MODE_CGX,
	},
	{	// -- BMPWIN_MDL_NAME --
		FRM_M_TEXT, 0, 22, BMP_M_CRS_NAME_W, 2, FONT_TALK_PAL, BMP_M_CRS_NAME_CGX,
	},
	{	// -- BMPWIN_RETURN --
		FRM_M_TEXT, 26, 21, BMP_M_RETURN_W, 2, FONT_TALK_PAL, BMP_M_RETURN_CGX,
	},
	// -- sub --
	{	// -- BMPWIN_S_CRS_NAME --
		FRM_S_TEXT, 9, 0, BMP_S_CRS_NAME_W, 2, FONT_TALK_PAL, BMP_S_CRS_NAME_CGX,
	},
	{	// -- BMPWIN_S_CAP --
		FRM_S_TEXT, 2, 2, BMP_S_CAP_W, 2, FONT_TALK_PAL, BMP_S_CAP_CGX,
	},
	{	// -- BMPWIN_S_THRON_NAME_01 --
		FRM_S_TEXT, 3, 6, BMP_S_THRON_NAME_01_W, 2, FONT_TALK_PAL, BMP_S_THRON_NAME_01_CGX,
	},
	{	// -- BMPWIN_S_THRON_NAME_02 --
		FRM_S_TEXT, 3, 8, BMP_S_THRON_NAME_02_W, 2, FONT_TALK_PAL, BMP_S_THRON_NAME_02_CGX,
	},
	{	// -- BMPWIN_S_THRON_NAME_03 --
		FRM_S_TEXT, 3, 10, BMP_S_THRON_NAME_03_W, 2, FONT_TALK_PAL, BMP_S_THRON_NAME_03_CGX,
	},
	{	// -- BMPWIN_S_THRON_SCORE_01 --
		FRM_S_TEXT, 22, 6, BMP_S_THRON_SCORE_01_W, 2, FONT_TALK_PAL, BMP_S_THRON_SCORE_01_CGX,
	},
	{	// -- BMPWIN_S_THRON_SCORE_02 --
		FRM_S_TEXT, 22, 8, BMP_S_THRON_SCORE_02_W, 2, FONT_TALK_PAL, BMP_S_THRON_SCORE_02_CGX,
	},
	{	// -- BMPWIN_S_THRON_SCORE_03 --
		FRM_S_TEXT, 22, 10, BMP_S_THRON_SCORE_03_W, 2, FONT_TALK_PAL, BMP_S_THRON_SCORE_03_CGX,
	},
	{	// -- BMPWIN_S_BONUS --
		FRM_S_TEXT, 7, 12, BMP_S_BONUS_W, 2, FONT_TALK_PAL, BMP_S_BONUS_CGX,
	},
	{	// -- BMPWIN_S_BONUS_SCORE --
		FRM_S_TEXT, 22, 12, BMP_S_BONUS_SCORE_W, 2, FONT_TALK_PAL, BMP_S_BONUS_SCORE_CGX,
	},
	{	// -- BMPWIN_S_TOTAL_SCORE_CAP --
		FRM_S_TEXT, 26, 22, BMP_S_TOTAL_SCORE_CAP_W, 2, FONT_TALK_PAL, BMP_S_TOTAL_SCORE_CAP_CGX,
	},
	{	// -- BMPWIN_S_RANK_01 --
		FRM_S_TEXT, 4, 16, BMP_S_RANK_01_W, 2, FONT_TALK_PAL, BMP_S_RANK_01_CGX,
	},
	{	// -- BMPWIN_S_RANK_02 --
		FRM_S_TEXT, 5, 19, BMP_S_RANK_02_W, 2, FONT_TALK_PAL, BMP_S_RANK_02_CGX,
	},
	{	// -- BMPWIN_S_RANK_03 --
		FRM_S_TEXT, 6, 22, BMP_S_RANK_03_W, 2, FONT_TALK_PAL, BMP_S_RANK_03_CGX,
	},
};

//=============================================================================
/**
 *								構造体定義
 */
//=============================================================================

//--------------------------------------------------------------
///	モジュール上で参照しか行わないデータ
//==============================================================
typedef struct {
	const PKTH_COURSE*	p_crs_dat;
	BOOL				b_museum_open;
} CONST_DATA;

//--------------------------------------------------------------
///	カーソルワーク
//==============================================================
typedef struct {
	s8 pos_idx;	///< @@@ pos_idx を廃止
	BOOL b_move_to_right;
} CURSOR_WORK;


//--------------------------------------------------------------
///	メインワーク
//==============================================================
typedef struct {
	const CONST_DATA*	wk_con;
	GF_BGL_INI*			p_bgl;
	ARCHANDLE*			p_arc_pkth_museum;
	HEAPID				heapID;

	MUSEUM_MSG_WORK*	wk_msg;
	MUSEUM_OBJ_WORK*	wk_obj;
	CATS_ACT_PTR		cap[ OBJ_ID_MAX ];

	CURSOR_WORK			wk_cur;

	COURSE_ID			crs_idx;
	BOOL				b_medal_move;
	BOOL				b_gph_flash;

} MUSEUM_COURSE_WORK;


//=============================================================================
/**
 *							プロトタイプ宣言
 */
//=============================================================================
// -- prototype --
PROC_RESULT MuseumCourseProc_Init( PROC *proc, int *seq);
PROC_RESULT MuseumCourseProc_End( PROC *proc,int *seq);
PROC_RESULT MuseumCourseProc_Main( PROC *proc,int *seq);
static void CONST_DATA_Create( MUSEUM_COURSE_WORK* wk, const PKTH_MUSEUM_COURSE_PARAM* p_param );
static BOOL CONST_DATA_GetMuseumFlag( const CONST_DATA* wk );
static void CONST_DATA_Release( const CONST_DATA* wk );
static const MONS_DATA* CONST_DATA_GetMonsDataPtr( const CONST_DATA* wk, COURSE_ID crs_idx, u8 poke_idx );
static u16 CONST_DATA_GetCourseScore( const CONST_DATA* wk, COURSE_ID idx );
static BOOL CONST_DATA_GetCourseClearFlag( const CONST_DATA* wk, COURSE_ID idx );
static u16 CONST_DATA_GetThronScore( const CONST_DATA* wk, COURSE_ID crs_idx, u16 event_idx );
static u32 CONST_DATA_GetEventIdx( const CONST_DATA* wk, COURSE_ID crs_idx, u8 event_idx );
static u16 CONST_DATA_GetMonsno( const CONST_DATA* wk, u8 crs_idx, u8 poke_idx );
static void BG_Init( MUSEUM_COURSE_WORK* wk );
static void BG_Release( MUSEUM_COURSE_WORK* wk );
static void BG_Load( MUSEUM_COURSE_WORK* wk );
static void BG_MEDAL_LoadScreen( MUSEUM_COURSE_WORK* wk, COURSE_ID idx, BOOL b_move_to_right );
static void BG_MEDAL_Move( MUSEUM_COURSE_WORK* wk );
static void BG_MEDAL_Flash( MUSEUM_COURSE_WORK* wk, COURSE_ID idx );
static void BMPWIN_Set( MUSEUM_COURSE_WORK* wk );
static void BMPWIN_Flash( MUSEUM_COURSE_WORK* wk, COURSE_ID idx );
static void PRINT_ThronScore( MUSEUM_COURSE_WORK* wk, COURSE_ID idx );
static void PRINT_RankName( MUSEUM_COURSE_WORK* wk, BOOL b_print );
static void PRINT_CourseName( MUSEUM_COURSE_WORK* wk, COURSE_ID idx );
static void PRINT_ObjScoreCap( MUSEUM_COURSE_WORK* wk );
static void COMMON_VBlank( void* work );
static void COMMON_Release( MUSEUM_COURSE_WORK* wk );
static void OBJ_Release( MUSEUM_COURSE_WORK * wk );
static void OBJ_LoadRes( MUSEUM_COURSE_WORK* wk );
static void OBJ_POEKGRA_LoadResDummy( MUSEUM_COURSE_WORK* wk );
static void OBJ_Set( MUSEUM_COURSE_WORK* wk );
static void OBJ_Enable( MUSEUM_COURSE_WORK* wk, BOOL b_enable );
static void OBJ_Flash( MUSEUM_COURSE_WORK* wk, COURSE_ID idx );
static BOOL CURSOR_Proc( MUSEUM_COURSE_WORK* wk );

//=============================================================================
/**
 *								外部公開関数
 */
//=============================================================================

//==============================================================================
/**
 *	@brief	プロセス初期化
 *	@param	proc	プロセスデータ
 *	@param	seq		シーケンス
 *
 *	@return	処理状況
 */
//==============================================================================
PROC_RESULT MuseumCourseProc_Init( PROC *proc, int *seq)
{
	enum { DEFAULT_COURSE_ID = COURSE_ID_SPEED, };

	MUSEUM_COURSE_WORK *wk = NULL;
	PKTH_MUSEUM_COURSE_PARAM * p_param;

	Overlay_Load( FS_OVERLAY_ID(pkthln_common), OVERLAY_LOAD_NOT_SYNCHRONIZE );

	p_param = (PKTH_MUSEUM_COURSE_PARAM*)PROC_GetParentWork( proc );

	GF_ASSERT( p_param );

	//ヒープ作成
	sys_CreateHeap( HEAPID_BASE_APP, HEAPID_PKTH_MUSEUM, 0x30000 );

	wk = PROC_AllocWork( proc, sizeof(MUSEUM_COURSE_WORK), HEAPID_PKTH_MUSEUM );
	MI_CpuClear8( wk, sizeof(MUSEUM_COURSE_WORK) );

	// パラメータ設定
	wk->heapID = HEAPID_PKTH_MUSEUM;
	wk->b_medal_move	= FALSE;
	wk->b_gph_flash		= TRUE;	// 初回更新のためTRUEにしておく
	wk->wk_cur.b_move_to_right = TRUE;

	// コンストデータ生成
	CONST_DATA_Create( wk, p_param );

	// 汎用初期化処理
	MUSEUM_COMMON_Init();

	// BG初期化
	BG_Init( wk );
	BG_Load( wk );
	wk->wk_msg = MUSEUM_BMPWIN_Create( wk->heapID, wk->p_bgl, BMPWIN_MAX, c_BmpWinList, NARC_msg_pokethlon_museum_dat );

	// OBJ初期化
	{
		TCATS_RESOURCE_NUM_LIST crnl = { CHR_ID_MAX, PAL_ID_MAX, CEL_ID_MAX, ANM_ID_MAX, 0 };
		wk->wk_obj = MUSEUM_OBJ_Create( wk->heapID, &crnl, OBJ_ID_MAX );
	}
	OBJ_LoadRes( wk );
	OBJ_Set( wk );
	OBJ_Enable( wk, FALSE );

	BG_MEDAL_Flash( wk, DEFAULT_COURSE_ID );
	BMPWIN_Flash( wk, DEFAULT_COURSE_ID );
	OBJ_Flash( wk, DEFAULT_COURSE_ID );

	// 文字列描画
	BMPWIN_Set( wk );

	// キーリピート速度設定
	sys_KeyRepeatSpeedSet( 2, 4 );

	WIPE_ResetWndMask( WIPE_DISP_MAIN );
	WIPE_ResetWndMask( WIPE_DISP_SUB );

	sys_VBlankFuncChange( COMMON_VBlank, wk );

	return PROC_RES_FINISH;
}


//==============================================================================
/**
 *	@brief	プロセス終了
 *	@param	proc	プロセスデータ
 *	@param	seq		シーケンス
 *
 *	@return	処理状況
 */
//==============================================================================
PROC_RESULT MuseumCourseProc_End( PROC *proc,int *seq)
{
	MUSEUM_COURSE_WORK* wk = PROC_GetWork(proc);

	sys_KeyRepeatSpeedSet( SYS_KEYREPEAT_SPEED_DEF, SYS_KEYREPEAT_WAIT_DEF );

	//コンストデータ開放
	CONST_DATA_Release( wk->wk_con );

	//ワークエリア解放
	PROC_FreeWork(proc);

	sys_DeleteHeap(HEAPID_PKTH_MUSEUM);

	Overlay_UnloadID( FS_OVERLAY_ID(pkthln_common) );

	return PROC_RES_FINISH;
}


//==============================================================================
/**
 *	@brief	プロセスメイン
 *	@param	proc	プロセスデータ
 *	@param	seq		シーケンス
 *
 *	@return	処理状況
 */
//==============================================================================
PROC_RESULT MuseumCourseProc_Main( PROC *proc,int *seq)
{
	enum
	{
		MAIN_SEQ_INIT = 0,
		MAIN_SEQ_FADE_IN,
		MAIN_SEQ_MAIN,
		MAIN_SEQ_FADE_OUT,
		MAIN_SEQ_END,
	};

	MUSEUM_COURSE_WORK* wk = PROC_GetWork(proc);

	BG_MEDAL_Move( wk );

	if( wk->b_gph_flash == TRUE )
	{
		BG_MEDAL_Flash( wk, wk->crs_idx );
		BMPWIN_Flash( wk, wk->crs_idx );
		OBJ_Flash( wk, wk->crs_idx );
		wk->b_gph_flash = FALSE;
		wk->b_medal_move = TRUE;
	}

	switch( *seq )
	{
		case MAIN_SEQ_INIT :
			WIPE_SYS_Start( WIPE_PATTERN_WMS, WIPE_TYPE_FADEIN, WIPE_TYPE_FADEIN,
							0x0000, COMM_BRIGHTNESS_SYNC, 1, wk->heapID );
			(*seq) = MAIN_SEQ_FADE_IN;
			break;

		case MAIN_SEQ_FADE_IN :
			if( WIPE_SYS_EndCheck() )
			{
				(*seq) = MAIN_SEQ_MAIN;
			}
			break;

		case MAIN_SEQ_MAIN :
			// 入力処理
			if( CURSOR_Proc( wk ) )
			{
				if( wk->b_medal_move == FALSE )
				{
					// アプリ終了
					Snd_SePlay( SEQ_SE_DP_SELECT );

					WIPE_SYS_Start( WIPE_PATTERN_WMS, WIPE_TYPE_FADEOUT, WIPE_TYPE_FADEOUT,
									0x0000, COMM_BRIGHTNESS_SYNC, 1, wk->heapID );
					(*seq) = MAIN_SEQ_FADE_OUT;
				}
			}
			break;

		case MAIN_SEQ_FADE_OUT :
			if( WIPE_SYS_EndCheck() )
			{
				(*seq) = MAIN_SEQ_END;
			}
			break;

		case MAIN_SEQ_END :
			// -- BG
			MUSEUM_BMPWIN_Delete( wk->wk_msg, BMPWIN_MAX );
			BG_Release( wk );

			// -- OBJ
			MUSEUM_OBJ_Delete( wk->wk_obj, wk->cap, OBJ_ID_MAX );

			MUSEUM_COMMON_Release();
			return PROC_RES_FINISH;

		default : GF_ASSERT( !"seq error!" );
	}

	MUSEUM_OBJ_Draw( wk->wk_obj );

	return PROC_RES_CONTINUE;
}


//=============================================================================
/**
 *								static関数
 */
//=============================================================================

//=============================================================================
/*
 *							データ取得関数群
 */
//=============================================================================

//-----------------------------------------------------------------------------
/**
 *	@brief	コンストデータ：生成
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void CONST_DATA_Create( MUSEUM_COURSE_WORK* wk, const PKTH_MUSEUM_COURSE_PARAM* p_param )
{
	CONST_DATA* cd;

	cd = sys_AllocMemory( wk->heapID, sizeof(CONST_DATA) );
	cd->p_crs_dat	= p_param->p_crs_dat;
	cd->b_museum_open = p_param->b_museum_open;

#ifdef PM_DEBUG
	// デバッグキーを押していたらパラメータを書き換えて全メダルを表示
	if( sys.cont & PAD_BUTTON_DEBUG )
	{
		int i;
		PKTH_COURSE* pCrs = (PKTH_COURSE*)(cd->p_crs_dat);

		for(i=0;i<COURSE_ID_MAX;i++)
		{
			pCrs[i].MaxScore = 1;
		}
	}
#endif

	wk->wk_con = cd;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	コンストデータ：ミュージアムフラグ取得
 *
 *	@param	const CONST_DATA* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static BOOL CONST_DATA_GetMuseumFlag( const CONST_DATA* wk )
{
	return wk->b_museum_open;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	コンストデータ：開放
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void CONST_DATA_Release( const CONST_DATA* wk )
{
	sys_FreeMemoryEz( (CONST_DATA*)wk );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	モンスターデータのポインタを取得
 *
 *	@param	const CONST_DATA* wk
 *	@param	crs_idx
 *	@param	poke_idx
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static const MONS_DATA* CONST_DATA_GetMonsDataPtr( const CONST_DATA* wk, COURSE_ID crs_idx, u8 poke_idx )
{
	return &wk->p_crs_dat[ crs_idx ].MonsData[ poke_idx ];
}

//-----------------------------------------------------------------------------
/**
 *	@brief	コース最高得点 取得
 *
 *	@param	const CONST_DATA* wk
 *	@param	idx
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u16 CONST_DATA_GetCourseScore( const CONST_DATA* wk, COURSE_ID idx )
{
	u16 scr = 0;

	GF_ASSERT( wk );
	GF_ASSERT( idx  < COURSE_ID_MAX );
	return wk->p_crs_dat[ idx ].MaxScore;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	コースクリアーフラグ取得
 *
 *	@param	const CONST_DATA* wk
 *	@param	idx
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static BOOL CONST_DATA_GetCourseClearFlag( const CONST_DATA* wk, COURSE_ID idx )
{
	GF_ASSERT( wk );

	return (CONST_DATA_GetCourseScore( wk, idx ) > 0);
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケスロンスコア取得
 *
 *	@param	const CONST_DATA* wk
 *	@param	crs_idx
 *	@param	event_idx
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u16 CONST_DATA_GetThronScore( const CONST_DATA* wk, COURSE_ID crs_idx, u16 event_idx )
{
	u16 score = 0;

	GF_ASSERT( wk );

	// ボーナス
	if( event_idx == 3 )
	{
		score = wk->p_crs_dat[ crs_idx ].MaxScore;
		score -= wk->p_crs_dat[ crs_idx ].EvtScore[0];
		score -= wk->p_crs_dat[ crs_idx ].EvtScore[1];
		score -= wk->p_crs_dat[ crs_idx ].EvtScore[2];
	}
	else
	{
		score = wk->p_crs_dat[ crs_idx ].EvtScore[ event_idx ];
	}

	return score;
}

#include "application\pokethlon_frame.h"
#include "..\pokethlon\pkthln_crs_tbl.dat"

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケスロン種目名メッセージのIDを取得
 *
 *	@param	const CONST_DATA* wk
 *	@param	crs_idx
 *	@param	event_idx
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u32 CONST_DATA_GetEventIdx( const CONST_DATA* wk, COURSE_ID crs_idx, u8 event_idx )
{
	GF_ASSERT( wk );
	GF_ASSERT( crs_idx < CRS_ID_NUM );
	GF_ASSERT( event_idx < PKTHLN_EVT_MAX_COMM );

	return crs_evt_tbl[ crs_idx ][ event_idx ];
}

//-----------------------------------------------------------------------------
/**
 *	@brief	モンスターナンバーを取得
 *
 *	@param	const CONST_DATA* wk
 *	@param	crs_idx
 *	@param	poke_idx
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u16 CONST_DATA_GetMonsno( const CONST_DATA* wk, u8 crs_idx, u8 poke_idx )
{
	GF_ASSERT( wk );
	GF_ASSERT( poke_idx < POKE_MAX );
	GF_ASSERT( crs_idx < COURSE_ID_MAX );

	return wk->p_crs_dat[ crs_idx ].MonsData[ poke_idx ].MonsNo;
}


//=============================================================================
/*
 *								BG操作
 */
//=============================================================================

//-----------------------------------------------------------------------------
/**
 *	@brief	BG 初期化
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *
 *	@retval	none
 */
//-----------------------------------------------------------------------------
static void BG_Init( MUSEUM_COURSE_WORK* wk )
{
	wk->p_bgl = GF_BGL_BglIniAlloc( wk->heapID );

	{	//BG SYSTEM
		GF_BGL_SYS_HEADER BGsys_data = {
			GX_DISPMODE_GRAPHICS,GX_BGMODE_0,GX_BGMODE_0,GX_BG0_AS_2D
		};
		GF_BGL_InitBG(&BGsys_data);
	}

	{
		int i;
		GF_BGL_BGCNT_HEADER TextBgCntDat[ BG_USE_NUM ] = {
			// -- MAIN --
			{	//FRM TEXT BG0
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0x0000,GX_BG_CHARBASE_0x04000,GX_BG_EXTPLTT_01,
				0,0,0,FALSE
			},
			{	//FRM BASE BG1
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0x0800,GX_BG_CHARBASE_0x08000,GX_BG_EXTPLTT_01,
				3,0,0,FALSE

			},
			{	//FRM MEDAL BG2
				0,0,0x1000,0,GF_BGL_SCRSIZ_512x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0x1000,GX_BG_CHARBASE_0x0c000,GX_BG_EXTPLTT_01,
				2,0,0,FALSE

			},
			{	//FRM WIN BG3
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0x2000,GX_BG_CHARBASE_0x14000,GX_BG_EXTPLTT_01,
				1,0,0,FALSE

			},
			// -- SUB --
			{	//SUB BASE BG0
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0xf800,GX_BG_CHARBASE_0x00000,GX_BG_EXTPLTT_01,
				3,0,0,FALSE
			},
			{	//SUB MEDAL BG1
				256,0,0x1000,0,GF_BGL_SCRSIZ_512x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0xe800,GX_BG_CHARBASE_0x04000,GX_BG_EXTPLTT_01,
				2,0,0,FALSE
			},
			{	//SUB TEXT BG2
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0xe000,GX_BG_CHARBASE_0x08000,GX_BG_EXTPLTT_01,
				0,0,0,FALSE
			},
			{	//SUB WIN BG3
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0xd800,GX_BG_CHARBASE_0x0c000,GX_BG_EXTPLTT_01,
				1,0,0,FALSE
			},
		};

		for(i = 0;i < BG_USE_NUM;i++){
			GF_BGL_BGControlSet(wk->p_bgl, c_BG_UseList[i], &(TextBgCntDat[i]), GF_BGL_MODE_TEXT);
			GF_BGL_ScrClear(wk->p_bgl, c_BG_UseList[i]);
			GF_BGL_ClearCharSet(c_BG_UseList[i], 32, 0, wk->heapID);
		}
	}

	// FRM_S_WIN FRM_M_WIN を半透明に
	G2_SetBlendAlpha(GX_BLEND_PLANEMASK_BG3, GX_BLEND_PLANEMASK_BG2, 15, 0 );
	G2S_SetBlendAlpha(GX_BLEND_PLANEMASK_BG3, GX_BLEND_PLANEMASK_BG1, 15, 0 );

	wk->p_arc_pkth_museum = ArchiveDataHandleOpen( ARC_PKTH_MUSEUM_GRA, wk->heapID );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	BG 開放
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *
 *	@retval	none
 */
//-----------------------------------------------------------------------------
static void BG_Release( MUSEUM_COURSE_WORK* wk )
{
	u8 i = 0;

	ArchiveDataHandleClose( wk->p_arc_pkth_museum );

	for( i=0; i<BG_USE_NUM; i++ )
	{
		GF_BGL_BGControlExit( wk->p_bgl, c_BG_UseList[i] );
	}

	sys_FreeMemoryEz( wk->p_bgl );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	BG リソースをロード
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BG_Load( MUSEUM_COURSE_WORK* wk )
{
	//--------------------------------------------
	// Main LCD
	ArcUtil_HDL_PalSet( wk->p_arc_pkth_museum, NARC_pkth_museum_course_bg_NCLR, PALTYPE_MAIN_BG,
					0, 0, wk->heapID );
	// -- base --
	ArcUtil_HDL_BgCharSet( wk->p_arc_pkth_museum, NARC_pkth_museum_course_bg_lz_NCGR,
					   wk->p_bgl, FRM_M_BASE, 0, 0, TRUE, wk->heapID );
	ArcUtil_HDL_ScrnSet( wk->p_arc_pkth_museum, NARC_pkth_museum_course_bg_lz_NSCR,
					 wk->p_bgl, FRM_M_BASE, 0, 0, TRUE, wk->heapID );
	// -- medal --
	ArcUtil_HDL_BgCharSet( wk->p_arc_pkth_museum, NARC_pkth_museum_medal_bg_lz_NCGR,
					   wk->p_bgl, FRM_M_MEDAL, 0, 0, TRUE, wk->heapID );
	// -- msgwin --
	ArcUtil_HDL_PalSet( wk->p_arc_pkth_museum, NARC_pkth_museum_course_bg_win_NCLR, PALTYPE_MAIN_BG,
					0x20*0xF, 0x20, wk->heapID );
	ArcUtil_HDL_BgCharSet( wk->p_arc_pkth_museum, NARC_pkth_museum_course_bg_win_lz_NCGR,
					   wk->p_bgl, FRM_M_WIN, 0, 0, TRUE, wk->heapID );
	ArcUtil_HDL_ScrnSet( wk->p_arc_pkth_museum, NARC_pkth_museum_course_bg_win_lz_NSCR,
					 wk->p_bgl, FRM_M_WIN, 0, 0, TRUE, wk->heapID );

	//--------------------------------------------
	// Sub LCD
	ArcUtil_HDL_PalSet( wk->p_arc_pkth_museum, NARC_pkth_museum_course_bg_sub_NCLR, PALTYPE_SUB_BG,
					0, 0, wk->heapID );
	// -- base --
	ArcUtil_HDL_BgCharSet( wk->p_arc_pkth_museum, NARC_pkth_museum_course_bg_sub_lz_NCGR,
					   wk->p_bgl, FRM_S_BASE, 0, 0, TRUE, wk->heapID );
	ArcUtil_HDL_ScrnSet( wk->p_arc_pkth_museum, NARC_pkth_museum_course_bg_sub_lz_NSCR,
					 wk->p_bgl, FRM_S_BASE, 0, 0, TRUE, wk->heapID );
	// -- medal --
	ArcUtil_HDL_BgCharSet( wk->p_arc_pkth_museum, NARC_pkth_museum_medal_bg_sub_lz_NCGR,
					   wk->p_bgl, FRM_S_MEDAL, 0, 0, TRUE, wk->heapID );

	// -- msgwin --
	ArcUtil_HDL_PalSet( wk->p_arc_pkth_museum, NARC_pkth_museum_course_bg_sub_win_NCLR, PALTYPE_SUB_BG,
					0x20*0xF, 0x20, wk->heapID );
	ArcUtil_HDL_BgCharSet( wk->p_arc_pkth_museum, NARC_pkth_museum_course_bg_sub_win_lz_NCGR,
					   wk->p_bgl, FRM_S_WIN, 0, 0, TRUE, wk->heapID );
	ArcUtil_HDL_ScrnSet( wk->p_arc_pkth_museum, NARC_pkth_museum_course_bg_sub_win_lz_NSCR,
					 wk->p_bgl, FRM_S_WIN, 0, 0, TRUE, wk->heapID );
}

// メダルに付随するOBJ (0=idx, 1=x, 1=y)
enum{ MEDAL_OBJ_MAX = 6, };
static const c_medal_obj_idx[ MEDAL_OBJ_MAX ][3] =
{
	{OBJ_ID_MEDAL_POKE_0, OBJPOS_MEDAL_POKE_0_X, OBJPOS_MEDAL_POKE_0_Y },
	{OBJ_ID_MEDAL_POKE_1, OBJPOS_MEDAL_POKE_1_X, OBJPOS_MEDAL_POKE_1_Y },
	{OBJ_ID_MEDAL_POKE_2, OBJPOS_MEDAL_POKE_2_X, OBJPOS_MEDAL_POKE_2_Y },
	{OBJ_ID_NUM_0, OBJPOS_NUM_0_X, OBJPOS_NUM_0_Y },
	{OBJ_ID_NUM_1, OBJPOS_NUM_1_X, OBJPOS_NUM_1_Y },
	{OBJ_ID_NUM_2, OBJPOS_NUM_2_X, OBJPOS_NUM_2_Y },
};

//-----------------------------------------------------------------------------
/**
 *	@brief	メダル用スクリーンをロード
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *	@param	idx
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BG_MEDAL_LoadScreen( MUSEUM_COURSE_WORK* wk, COURSE_ID idx, BOOL b_move_to_right )
{
	static const scr_tbl[][2] =
	{
		{ NARC_pkth_museum_medal_a_bg_lz_NSCR, NARC_pkth_museum_medal_a_bg_sub_lz_NSCR },
		{ NARC_pkth_museum_medal_b_bg_lz_NSCR, NARC_pkth_museum_medal_b_bg_sub_lz_NSCR },
		{ NARC_pkth_museum_medal_c_bg_lz_NSCR, NARC_pkth_museum_medal_c_bg_sub_lz_NSCR },
		{ NARC_pkth_museum_medal_d_bg_lz_NSCR, NARC_pkth_museum_medal_d_bg_sub_lz_NSCR },
		{ NARC_pkth_museum_medal_e_bg_lz_NSCR, NARC_pkth_museum_medal_e_bg_sub_lz_NSCR },
	};

	int move_val = b_move_to_right ? -256 : 256;

	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG2	, FALSE );
	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_BG1, FALSE );

	ArcUtil_HDL_ScrnSet( wk->p_arc_pkth_museum, scr_tbl[idx][0], wk->p_bgl, FRM_M_MEDAL, 0, 0, TRUE, wk->heapID );
	ArcUtil_HDL_ScrnSet( wk->p_arc_pkth_museum, scr_tbl[idx][1], wk->p_bgl, FRM_S_MEDAL, 0, 0, TRUE, wk->heapID );

	GF_BGL_ScrollSet( wk->p_bgl, FRM_M_MEDAL, GF_BGL_SCROLL_X_SET, move_val );
	GF_BGL_ScrollSet( wk->p_bgl, FRM_S_MEDAL, GF_BGL_SCROLL_X_SET, move_val );

	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG2	, TRUE );
	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_BG1, TRUE );

	//-- メダルについているOBJも移動
	{
		u8 i;
		for( i=0; i<MEDAL_OBJ_MAX; i++ )
		{
			CATS_ObjectPosMoveCap( wk->cap[ c_medal_obj_idx[i][0] ], -move_val, 0 );
		}
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	メタルの移動処理
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BG_MEDAL_Move( MUSEUM_COURSE_WORK* wk )
{
	int posx;
	int pre;

	if( wk->b_medal_move == FALSE ){ return; }

	posx =  GF_BGL_ScrollGetX( wk->p_bgl, FRM_M_MEDAL );
	pre = posx;

	posx >>= 2;
	if( pre == posx ){ posx = 0; }

	GF_BGL_ScrollReq( wk->p_bgl, FRM_M_MEDAL, GF_BGL_SCROLL_X_SET, posx );
	GF_BGL_ScrollReq( wk->p_bgl, FRM_S_MEDAL, GF_BGL_SCROLL_X_SET, posx );

	//-- メダルについているOBJも移動
	{
		u8 i;
		for( i=0; i<MEDAL_OBJ_MAX; i++ )
		{
			CATS_ObjectPosSetCap( wk->cap[ c_medal_obj_idx[i][0] ], c_medal_obj_idx[i][1] - posx, c_medal_obj_idx[i][2] );
		}
	}

	if( posx == 0 )
	{
		wk->b_medal_move = FALSE;
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	BGメダルを更新
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *	@param	idx
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BG_MEDAL_Flash( MUSEUM_COURSE_WORK* wk, COURSE_ID idx )
{
	// メダルBG表示
	if( CONST_DATA_GetCourseClearFlag( wk->wk_con, idx ) )
	{
		//@@@ べたアクセス
		CURSOR_WORK* cwk = &wk->wk_cur;
		BG_MEDAL_LoadScreen( wk, idx, cwk->b_move_to_right );
	}
	// メダルBG非表示
	else
	{
		GF_BGL_ScrClear( wk->p_bgl, FRM_M_MEDAL );
		GF_BGL_ScrClear( wk->p_bgl, FRM_S_MEDAL );
	}
}




//-----------------------------------------------------------------------------
/**
 *	@brief	BMPWIN 固定メッセージを一斉表示
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *
 *	@retval	none
 */
//-----------------------------------------------------------------------------
static void BMPWIN_Set( MUSEUM_COURSE_WORK* wk )
{
	MUSEUM_MSG_WORK* p_msg = wk->wk_msg;

	MUSEUM_BMPWIN_PrintAndSetOfs( wk->wk_msg, BMPWIN_MODE, msg_pkthRNK_crs, 1, 0 );
	MUSEUM_BMPWIN_PrintEx( wk->wk_msg, BMPWIN_RETURN, msg_pkthRNK_return, FALSE, 0, FONT_TOUCH );
	MUSEUM_BMPWIN_Print( wk->wk_msg, BMPWIN_S_BONUS, msg_pkthRNK_crsbonus, FALSE );
}


//-----------------------------------------------------------------------------
/**
 *	@brief	BMPWINの更新
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *	@param	idx
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BMPWIN_Flash( MUSEUM_COURSE_WORK* wk, COURSE_ID idx )
{
	PRINT_CourseName( wk, idx );
	PRINT_ThronScore( wk, idx );
	PRINT_RankName( wk, CONST_DATA_GetCourseClearFlag( wk->wk_con, idx ) );
	PRINT_ObjScoreCap( wk );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケスロン：スコアを表示
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *	@param	idx
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PRINT_ThronScore( MUSEUM_COURSE_WORK* wk, COURSE_ID idx )
{
	static const win_tbl[][2] = {
		{ BMPWIN_S_THRON_NAME_01, BMPWIN_S_THRON_SCORE_01 },
		{ BMPWIN_S_THRON_NAME_02, BMPWIN_S_THRON_SCORE_02 },
		{ BMPWIN_S_THRON_NAME_03, BMPWIN_S_THRON_SCORE_03 },
	};

	int i;
	MUSEUM_MSG_WORK* p_msg = wk->wk_msg;
	WORDSET* wset = MUSEUM_BMPWIN_GetWordset( wk->wk_msg );

	for( i=0; i<POKE_MAX; i++ )
	{
		int event_idx = CONST_DATA_GetEventIdx( wk->wk_con, idx, i );

		WORDSET_RegisterPkthlnMatch( wset, 1, event_idx );
		MUSEUM_BMPWIN_PrintNum( wk->wk_msg, win_tbl[i][0], msg_pkthRNK_thron_name, i+1, 1, 0 );
		if( CONST_DATA_GetCourseClearFlag( wk->wk_con, idx ) )
		{
			MUSEUM_BMPWIN_PrintNum( wk->wk_msg, win_tbl[i][1], msg_pkthRNK_crsten, CONST_DATA_GetThronScore(wk->wk_con, idx, i), 3, 0 );
		}
		else
		{
			MUSEUM_BMPWIN_Print( wk->wk_msg, win_tbl[i][1], msg_pkthRNK_crsten_off, FALSE );
		}

	}
	// -- ボーナス点
	if( CONST_DATA_GetCourseClearFlag( wk->wk_con, idx ) )
	{
		MUSEUM_BMPWIN_PrintNum( wk->wk_msg, BMPWIN_S_BONUS_SCORE, msg_pkthRNK_crsten, CONST_DATA_GetThronScore(wk->wk_con, idx, 3), 3, 0 );
	}
	else
	{
		MUSEUM_BMPWIN_Print( wk->wk_msg, BMPWIN_S_BONUS_SCORE, msg_pkthRNK_crsten_off, FALSE );
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ランクインしたポケモンの名前を表示
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *	@param	b_print	FALSEならクリアのみ
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PRINT_RankName( MUSEUM_COURSE_WORK* wk, BOOL b_print )
{
	int i;
	MUSEUM_MSG_WORK* p_msg = wk->wk_msg;


	for( i=0; i<POKE_MAX; i++ )
	{
		if( b_print )
		{
			u16 monsno = CONST_DATA_GetMonsno( wk->wk_con, wk->crs_idx, i );
			MUSEUM_BMPWIN_PrintPokemonName( p_msg, BMPWIN_S_RANK_01 + i, monsno );
		}
		else
		{
			MUSEUM_BMPWIN_ClearAndTransReq( p_msg, BMPWIN_S_RANK_01 + i );
		}
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	表示コースに応じた文字列を表示
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PRINT_CourseName( MUSEUM_COURSE_WORK* wk, COURSE_ID idx )
{
	MUSEUM_MSG_WORK* p_msg = wk->wk_msg;
	WORDSET* wset = MUSEUM_BMPWIN_GetWordset( p_msg );

	// メダル名
	WORDSET_RegisterPkthlnMedal( wset, 0, idx );
	MUSEUM_BMPWIN_PrintAndSetOfs( wk->wk_msg, BMPWIN_MDL_NAME, msg_pkthRNK_mdl, 1, 0 );
	// コース名
	WORDSET_RegisterPkthlnCourse( wset, 0, idx );
	MUSEUM_BMPWIN_Print( wk->wk_msg, BMPWIN_S_CRS_NAME, msg_pkthRNK_crsname, TRUE );

	// ミュージアム4開放フラグをチェック
	if( CONST_DATA_GetMuseumFlag( wk->wk_con ) )
	{
		u16 score;
		MUSEUM_TROPHY trophy;

		score = CONST_DATA_GetCourseScore( wk->wk_con, idx );
		trophy = MUSEUM_UTIL_GetCourseTrophyCount( score );

		if( trophy == MUSEUM_TROPHY_NONE )
		{
			MUSEUM_BMPWIN_Print( wk->wk_msg, BMPWIN_S_CAP, msg_pkthRNK_crstrophy_01, TRUE );
		}
		else if( trophy == MUSEUM_TROPHY_SINGLE )
		{
			MUSEUM_BMPWIN_Print( wk->wk_msg, BMPWIN_S_CAP, msg_pkthRNK_crstrophy_02, TRUE );
		}
		else
		{
			GF_BGL_BmpWinDataFill( &p_msg->win[ BMPWIN_S_CAP ], COL_NL );
			GF_BGL_BmpWinOnVReq( &p_msg->win[ BMPWIN_S_CAP ] );
		}
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	合計点を描画
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PRINT_ObjScoreCap( MUSEUM_COURSE_WORK* wk )
{
	MUSEUM_MSG_WORK* p_msg = wk->wk_msg;

	if( CONST_DATA_GetCourseClearFlag( wk->wk_con, wk->crs_idx ) )
	{
		MUSEUM_BMPWIN_Print( wk->wk_msg, BMPWIN_S_TOTAL_SCORE_CAP, msg_pkthRNK_ten_cap, FALSE );
	}
	else
	{
		GF_BGL_BmpWinDataFill( &p_msg->win[ BMPWIN_S_TOTAL_SCORE_CAP ], COL_NL );
		GF_BGL_BmpWinOnVReq( &p_msg->win[ BMPWIN_S_TOTAL_SCORE_CAP ] );
	}

}

//-----------------------------------------------------------------------------
/**
 *	@brief	VBlank処理
 *
 *	@param	* work
 *
 *	@retval	none
 */
//-----------------------------------------------------------------------------
static void COMMON_VBlank( void* work )
{
	MUSEUM_COURSE_WORK* wk = work;

	CATS_RenderOamTrans();
	GF_BGL_VBlankFunc( wk->p_bgl );
	OS_SetIrqCheckFlag( OS_IE_V_BLANK );
}



//-------------------------------------------------------------------------------------------------
/**
 *		OBJ関係
 */
//-------------------------------------------------------------------------------------------------


//-----------------------------------------------------------------------------
/**
 *	@brief	OBJリソースロード
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_LoadRes( MUSEUM_COURSE_WORK* wk )
{
	CATS_SYS_PTR	csp = MUSEUM_OBJ_GetCsp( wk->wk_obj );
	CATS_RES_PTR	crp = MUSEUM_OBJ_GetCrp( wk->wk_obj );
	//------------------------------------------------------------------------------------------
	// Main LCD

	// -- course_obj --
	CATS_LoadResourceCharArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_course_obj_lz_NCGR, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_M_COURSE );

	CATS_LoadResourcePlttArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_course_obj_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_M_COURSE );

	CATS_LoadResourceCellArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_course_obj_lz_NCER, TRUE, CEL_ID_COURSE );

	CATS_LoadResourceCellAnmArcH( csp, crp,  wk->p_arc_pkth_museum,
			NARC_pkth_museum_course_obj_lz_NANR, TRUE, ANM_ID_COURSE );

	// -- obj_trophy --
	CATS_LoadResourceCharArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_trophy_lz_NCGR, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_M_TROPHY );

	CATS_LoadResourcePlttArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_trophy_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_M_TROPHY );

	CATS_LoadResourceCellArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_trophy_lz_NCER, TRUE, CEL_ID_TROPHY );

	CATS_LoadResourceCellAnmArcH( csp, crp,  wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_trophy_lz_NANR, TRUE, ANM_ID_TROPHY );

	// -- obj_medal --
	CATS_LoadResourceCharArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_medal_lz_NCGR, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_M_MEDAL );

	CATS_LoadResourcePlttArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_medal_NCLR, 0, 5, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_M_MEDAL );

	CATS_LoadResourceCellArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_medal_lz_NCER, TRUE, CEL_ID_MEDAL );

	CATS_LoadResourceCellAnmArcH( csp, crp,  wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_medal_lz_NANR, TRUE, ANM_ID_MEDAL );


	//------------------------------------------------------------------------------------------
	// Sub LCD

	// -- obj_num_big --
	CATS_LoadResourceCharArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_num_big_lz_NCGR, TRUE, NNS_G2D_VRAM_TYPE_2DSUB, CHR_ID_S_NUM );

	CATS_LoadResourcePlttArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_num_big_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DSUB, PAL_ID_S_NUM );

	CATS_LoadResourceCellArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_num_big_lz_NCER, TRUE, CEL_ID_S_NUM );

	CATS_LoadResourceCellAnmArcH( csp, crp,  wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_num_big_lz_NANR, TRUE, ANM_ID_S_NUM );



	//------------------------------------------------------------------------------------------

	OBJ_POEKGRA_LoadResDummy( wk );

	{
		static const MUSEUM_OBJ_ID c_pkicon_id = {
			CHR_ID_S_POKEICON_0, PAL_ID_S_POKEICON, CEL_ID_POKEICON, ANM_ID_POKEICON,
		};
		MUSEUM_OBJ_POKEICON_LoadRes( wk->wk_obj, &c_pkicon_id, POKE_MAX, FALSE, TRUE );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモングラフィックリソース読み込み
 *
 * @param	appwk	ボックス画面アプリワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void OBJ_POEKGRA_LoadResDummy( MUSEUM_COURSE_WORK* wk )
{
	static const MUSEUM_OBJ_ID idx_tbl[4] = {
		{ CHR_ID_M_POKEGRA_0, PAL_ID_M_POKEGRA_0, CEL_ID_POKEGRA, ANM_ID_POKEGRA, },
		{ CHR_ID_M_POKEGRA_1, PAL_ID_M_POKEGRA_1, CEL_ID_POKEGRA, ANM_ID_POKEGRA, },
		{ CHR_ID_M_POKEGRA_2, PAL_ID_M_POKEGRA_2, CEL_ID_POKEGRA, ANM_ID_POKEGRA, },
	};

	u8 i;
	CATS_SYS_PTR	csp = MUSEUM_OBJ_GetCsp( wk->wk_obj );
	CATS_RES_PTR	crp = MUSEUM_OBJ_GetCrp( wk->wk_obj );

	for( i=0; i<POKE_MAX; i++ )
	{
		MUSEUM_OBJ_POKEGRA_LoadResDummy( csp, crp, &idx_tbl[i], NNS_G2D_VRAM_TYPE_2DMAIN );
	}

}

//---------------------------------------------------------------------------------------------
/**
 * セルアクター追加
 *
 * @param	wk		ワーク
 *
 */
//---------------------------------------------------------------------------------------------
static void OBJ_Set( MUSEUM_COURSE_WORK* wk )
{
	static const TCATS_OBJECT_ADD_PARAM_S	ActAddParam[ OBJ_ID_MAX ] =
	{
		//-- Main LCD --

		{	// -- MEDAL_CORSOR --
			OBJPOS_MEDAL_SPEED_X,	OBJPOS_MEDAL_SPEED_Y,	0,
			NANR_obj_trophy_cur, 2, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_TROPHY, PAL_ID_M_TROPHY, CEL_ID_TROPHY, ANM_ID_TROPHY, 0, 0 },
			3, FALSE,
		},
		{	// -- MEDAL_SPEED --
			OBJPOS_MEDAL_SPEED_X,	OBJPOS_MEDAL_SPEED_Y,	0,
			OBJ_ANM_MEDAL_SPD, 2, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_MEDAL, PAL_ID_M_MEDAL, CEL_ID_MEDAL, ANM_ID_MEDAL, 0, 0 },
			3, FALSE,
		},
		{	// -- MEDAL_POWER --
			OBJPOS_MEDAL_POWER_X,	OBJPOS_MEDAL_POWER_Y,	0,
			OBJ_ANM_MEDAL_POW, 2, 1, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_MEDAL, PAL_ID_M_MEDAL, CEL_ID_MEDAL, ANM_ID_MEDAL, 0, 0 },
			3, FALSE,
		},
		{	// -- MEDAL_TECHNIC --
			OBJPOS_MEDAL_TOCHNIC_X,	OBJPOS_MEDAL_TOCHNIC_Y,	0,
			OBJ_ANM_MEDAL_TEC, 2, 2, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_MEDAL, PAL_ID_M_MEDAL, CEL_ID_MEDAL, ANM_ID_MEDAL, 0, 0 },
			3, FALSE,
		},
		{	// -- MEDAL_STAMINA --
			OBJPOS_MEDAL_STAMINA_X,	OBJPOS_MEDAL_STAMINA_Y,	0,
			OBJ_ANM_MEDAL_STA, 2, 3, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_MEDAL, PAL_ID_M_MEDAL, CEL_ID_MEDAL, ANM_ID_MEDAL, 0, 0 },
			3, FALSE,
		},
		{	// -- MEDAL_JUMP --
			OBJPOS_MEDAL_JUMP_X,	OBJPOS_MEDAL_JUMP_Y,	0,
			OBJ_ANM_MEDAL_JMP, 2, 4, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_MEDAL, PAL_ID_M_MEDAL, CEL_ID_MEDAL, ANM_ID_MEDAL, 0, 0 },
			3, FALSE,
		},
		{	// -- MEDAL_SPEED_EFF --
			OBJPOS_MEDAL_SPEED_X,	OBJPOS_MEDAL_SPEED_Y,	0,
			NANR_obj_trophy_trp_single_r, 1, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_TROPHY, PAL_ID_M_TROPHY, CEL_ID_TROPHY, ANM_ID_TROPHY, 0, 0 },
			3, FALSE,
		},
		{	// -- MEDAL_POWER_EFF --
			OBJPOS_MEDAL_POWER_X,	OBJPOS_MEDAL_POWER_Y,	0,
			NANR_obj_trophy_trp_single_l, 1, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_TROPHY, PAL_ID_M_TROPHY, CEL_ID_TROPHY, ANM_ID_TROPHY, 0, 0 },
			3, FALSE,
		},
		{	// -- MEDAL_TECHNIC_EFF --
			OBJPOS_MEDAL_TOCHNIC_X,	OBJPOS_MEDAL_TOCHNIC_Y,	0,
			NANR_obj_trophy_trp_single_r, 1, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_TROPHY, PAL_ID_M_TROPHY, CEL_ID_TROPHY, ANM_ID_TROPHY, 0, 0 },
			3, FALSE,
		},
		{	// -- MEDAL_STAMINA_EFF --
			OBJPOS_MEDAL_STAMINA_X,	OBJPOS_MEDAL_STAMINA_Y,	0,
			NANR_obj_trophy_trp_single_l, 1, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_TROPHY, PAL_ID_M_TROPHY, CEL_ID_TROPHY, ANM_ID_TROPHY, 0, 0 },
			3, FALSE,
		},
		{	// -- MEDAL_JUMP_EFF --
			OBJPOS_MEDAL_JUMP_X,	OBJPOS_MEDAL_JUMP_Y,	0,
			NANR_obj_trophy_trp_single_r, 1, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_TROPHY, PAL_ID_M_TROPHY, CEL_ID_TROPHY, ANM_ID_TROPHY, 0, 0 },
			3, FALSE,
		},
		{	// -- MEDAL_POKE_0 --
			OBJPOS_MEDAL_POKE_0_X,	OBJPOS_MEDAL_POKE_0_Y,	0,
			0, 2, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_POKEGRA_0, PAL_ID_M_POKEGRA_0, CEL_ID_POKEGRA, ANM_ID_POKEGRA, 0, 0 },
			0, FALSE,
		},
		{	// -- MEDAL_POKE_1 --
			OBJPOS_MEDAL_POKE_1_X,	OBJPOS_MEDAL_POKE_1_Y,	0,
			0, 1, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_POKEGRA_1, PAL_ID_M_POKEGRA_1, CEL_ID_POKEGRA, ANM_ID_POKEGRA, 0, 0 },
			0, FALSE,
		},
		{	// -- MEDAL_POKE_2 --
			OBJPOS_MEDAL_POKE_2_X,	OBJPOS_MEDAL_POKE_2_Y,	0,
			0, 1, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_POKEGRA_2, PAL_ID_M_POKEGRA_2, CEL_ID_POKEGRA, ANM_ID_POKEGRA, 0, 0 },
			0, FALSE,
		},
		{	// -- NUM_0 --
			OBJPOS_NUM_0_X,	OBJPOS_NUM_0_Y,	0,
			NANR_course_obj_num0, 1, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_COURSE, PAL_ID_M_COURSE, CEL_ID_COURSE, ANM_ID_COURSE, 0, 0 },
			0, FALSE,
		},
		{	// -- NUM_1 --
			OBJPOS_NUM_1_X,	OBJPOS_NUM_1_Y,	0,
			NANR_course_obj_num1, 1, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_COURSE, PAL_ID_M_COURSE, CEL_ID_COURSE, ANM_ID_COURSE, 0, 0 },
			0, FALSE,
		},
		{	// -- NUM_2 --
			OBJPOS_NUM_2_X,	OBJPOS_NUM_2_Y,	0,
			NANR_course_obj_num2, 1, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_COURSE, PAL_ID_M_COURSE, CEL_ID_COURSE, ANM_ID_COURSE, 0, 0 },
			0, FALSE,
		},
		{	// -- OBJ_ID_EFF_0 --
			OBJPOS_EFF_0_X,	OBJPOS_EFF_0_Y,	0,
			NANR_course_obj_eff0, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_COURSE, PAL_ID_M_COURSE, CEL_ID_COURSE, ANM_ID_COURSE, 0, 0 },
			0, FALSE,
		},
		{	// -- OBJ_ID_EFF_1 --
			OBJPOS_EFF_1_X,	OBJPOS_EFF_1_Y,	0,
			NANR_course_obj_eff1, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_COURSE, PAL_ID_M_COURSE, CEL_ID_COURSE, ANM_ID_COURSE, 0, 0 },
			0, FALSE,
		},
		{	// -- OBJ_ID_EFF_2 --
			OBJPOS_EFF_2_X,	OBJPOS_EFF_2_Y,	0,
			NANR_course_obj_eff2, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_COURSE, PAL_ID_M_COURSE, CEL_ID_COURSE, ANM_ID_COURSE, 0, 0 },
			0, FALSE,
		},

		//
		//-- Sub LCD --
		{	// -- OBJ_ID_S_NUM_0 --
			OBJPOS_S_NUM_0_X,	OBJPOS_S_NUM_0_Y,	0,
			0, 1, 0, NNS_G2D_VRAM_TYPE_2DSUB,
			{ CHR_ID_S_NUM, PAL_ID_S_NUM, CEL_ID_S_NUM, ANM_ID_S_NUM, 0, 0 },
			0, FALSE,
		},
		{	// -- OBJ_ID_S_NUM_1 --
			OBJPOS_S_NUM_1_X,	OBJPOS_S_NUM_1_Y,	0,
			1, 1, 0, NNS_G2D_VRAM_TYPE_2DSUB,
			{ CHR_ID_S_NUM, PAL_ID_S_NUM, CEL_ID_S_NUM, ANM_ID_S_NUM, 0, 0 },
			0, FALSE,
		},
		{	// -- OBJ_ID_S_NUM_2 --
			OBJPOS_S_NUM_2_X,	OBJPOS_S_NUM_2_Y,	0,
			2, 1, 0, NNS_G2D_VRAM_TYPE_2DSUB,
			{ CHR_ID_S_NUM, PAL_ID_S_NUM, CEL_ID_S_NUM, ANM_ID_S_NUM, 0, 0 },
			0, FALSE,
		},
		{	 // -- OBJ_ID_S_POKE_0 --
			16, 128, 0,
			0, 1, 0, NNS_G2D_VRAM_TYPE_2DSUB,
			{ CHR_ID_S_POKEICON_0, PAL_ID_S_POKEICON, CEL_ID_POKEICON, ANM_ID_POKEICON, 0, 0 },
			0, FALSE,
		},
		{	 // -- OBJ_ID_S_POKE_1 --
			24, 128+24, 0,
			0, 1, 0, NNS_G2D_VRAM_TYPE_2DSUB,
			{ CHR_ID_S_POKEICON_1, PAL_ID_S_POKEICON, CEL_ID_POKEICON, ANM_ID_POKEICON, 0, 0 },
			0, FALSE,
		},
		{	 // -- OBJ_ID_S_POKE_2 --
			32, 128+24*2, 0,
			0, 1, 0, NNS_G2D_VRAM_TYPE_2DSUB,
			{ CHR_ID_S_POKEICON_2, PAL_ID_S_POKEICON, CEL_ID_POKEICON, ANM_ID_POKEICON, 0, 0 },
			0, FALSE,
		},
	};

	int i;

	// COMMON OBJ初期化
	for( i=0; i < OBJ_ID_MAX; i++ )
	{
		wk->cap[ i ] = MUSEUM_OBJ_Add( wk->wk_obj, &ActAddParam[ i ] );
		CATS_ObjectAutoAnimeSetCap( wk->cap[ i ], TRUE );
	};

	// メダル表示判定
	for( i=0; i<COURSE_ID_MAX; i++ )
	{
		enum{ START_OBJ_IDX = OBJ_ID_MEDAL_SPEED, EFF_DIFF = COURSE_ID_MAX, };

		// -- メダル表示判定 --
		if( CONST_DATA_GetCourseClearFlag( wk->wk_con, i ) == FALSE )
		{
			CATS_ObjectEnableCap( wk->cap[ START_OBJ_IDX + i ], CATS_ENABLE_FALSE );
		}

		// -- トロフィー表示判定 --
		{
			u16 score = CONST_DATA_GetCourseScore( wk->wk_con, i );
			MUSEUM_TROPHY trophy;

			trophy = MUSEUM_UTIL_GetCourseTrophyCount( score );

			if( trophy == MUSEUM_TROPHY_DOUBLE )
			{
				// ダブルトロフィー
				if( i%2 == 0 )
				{
					CATS_ObjectAnimeSeqSetCap( wk->cap[ START_OBJ_IDX + i + EFF_DIFF ], NANR_obj_trophy_trp_double_r );
				}
				else
				{
					CATS_ObjectAnimeSeqSetCap( wk->cap[ START_OBJ_IDX + i + EFF_DIFF ], NANR_obj_trophy_trp_double_l );
				}
			}
			else if( trophy == MUSEUM_TROPHY_SINGLE )
			{
				// トロフィー表示
				if( i%2 == 0 )
				{
					CATS_ObjectAnimeSeqSetCap( wk->cap[ START_OBJ_IDX + i + EFF_DIFF ], NANR_obj_trophy_trp_single_r );
				}
				else
				{
					CATS_ObjectAnimeSeqSetCap( wk->cap[ START_OBJ_IDX + i + EFF_DIFF ], NANR_obj_trophy_trp_single_l );
				}
			}
			else
			{
				// トロフィー非表示
				CATS_ObjectEnableCap( wk->cap[ START_OBJ_IDX + i + EFF_DIFF ], CATS_ENABLE_FALSE );
			}
		}
	}

}

//-----------------------------------------------------------------------------
/**
 *	@brief	読み替えするOBJの表示設定を設定
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_Enable( MUSEUM_COURSE_WORK* wk, BOOL b_enable )
{
	CATS_ObjectEnableCap( wk->cap[ OBJ_ID_NUM_0 ], b_enable );
	CATS_ObjectEnableCap( wk->cap[ OBJ_ID_NUM_1 ], b_enable );
	CATS_ObjectEnableCap( wk->cap[ OBJ_ID_NUM_2 ], b_enable );
	CATS_ObjectEnableCap( wk->cap[ OBJ_ID_MEDAL_POKE_0 ], b_enable );
	CATS_ObjectEnableCap( wk->cap[ OBJ_ID_MEDAL_POKE_1 ], b_enable );
	CATS_ObjectEnableCap( wk->cap[ OBJ_ID_MEDAL_POKE_2 ], b_enable );
	CATS_ObjectEnableCap( wk->cap[ OBJ_ID_EFF_0 ], b_enable );
	CATS_ObjectEnableCap( wk->cap[ OBJ_ID_EFF_1 ], b_enable );
	CATS_ObjectEnableCap( wk->cap[ OBJ_ID_EFF_2 ], b_enable );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	指定コースのOBJ数値を描画
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_Flash( MUSEUM_COURSE_WORK* wk, COURSE_ID idx )
{
	enum{ SCORE_FIG = 3, OBJ_EFF_MAX = 3, };

	// -- 数字OBJテーブル：小 --
	static const anm_tbl[] =
	{
		NANR_course_obj_num0, NANR_course_obj_num1, NANR_course_obj_num2, NANR_course_obj_num3,	NANR_course_obj_num4,
		NANR_course_obj_num5, NANR_course_obj_num6, NANR_course_obj_num7, NANR_course_obj_num8, NANR_course_obj_num9,
	};

	u8 i;
	u16 score;

	score = CONST_DATA_GetCourseScore( wk->wk_con, idx );

	// SCORE
	for( i=0; i<SCORE_FIG; i++ )
	{
		if( CONST_DATA_GetCourseClearFlag( wk->wk_con, idx ) == TRUE )
		{
			u16 fig;

			fig = UTIL_GetFigreAppoint( score, i+1 );
			CATS_ObjectAnimeSeqSetCap( wk->cap[ OBJ_ID_S_NUM_0 + i ], fig );
			CATS_ObjectAnimeSeqSetCap( wk->cap[ OBJ_ID_NUM_0 + i ], anm_tbl[ fig ] );
			CATS_ObjectEnableCap( wk->cap[ OBJ_ID_NUM_0 + i ], CATS_ENABLE_TRUE );
			CATS_ObjectEnableCap( wk->cap[ OBJ_ID_S_NUM_0 + i ], CATS_ENABLE_TRUE );
		}
		else
		{
			CATS_ObjectEnableCap( wk->cap[ OBJ_ID_NUM_0 + i ], CATS_ENABLE_FALSE );
			CATS_ObjectEnableCap( wk->cap[ OBJ_ID_S_NUM_0 + i ], CATS_ENABLE_FALSE );
		}
	}

	// POKEGRA, POKEICON
	for( i=0; i<POKE_MAX; i++ )
	{
		const MONS_DATA* p_mons;

		p_mons = CONST_DATA_GetMonsDataPtr( wk->wk_con, idx, i );

		if( CONST_DATA_GetCourseClearFlag( wk->wk_con, idx ) == TRUE )
		{
			MUSEUM_OBJ_POKEGRA_Trans( wk->cap[ OBJ_ID_MEDAL_POKE_0 + i ], p_mons, TRUE, FALSE, wk->heapID );
			CATS_ObjectEnableCap( wk->cap[ OBJ_ID_MEDAL_POKE_0 + i ], TRUE );

			MUSEUM_OBJ_POKEICON_Draw( wk->wk_obj, wk->cap[ OBJ_ID_S_POKE_0 + i ], p_mons, FALSE, TRUE );
			CATS_ObjectEnableCap( wk->cap[ OBJ_ID_S_POKE_0 + i ], TRUE );
		}
		else
		{
			CATS_ObjectEnableCap( wk->cap[ OBJ_ID_S_POKE_0 + i ], FALSE );
		}
	}

	// エフェクト
	for( i=0; i<OBJ_EFF_MAX; i++ )
	{
		BOOL flag = CONST_DATA_GetCourseClearFlag( wk->wk_con, idx );
		CATS_ObjectEnableCap( wk->cap[ OBJ_ID_EFF_0 + i ], flag );
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	カーソル処理
 *
 *	@param	MUSEUM_COURSE_WORK* wk
 *
 *	@retval	TRUE:PROC終了
 */
//-----------------------------------------------------------------------------
static BOOL CURSOR_Proc( MUSEUM_COURSE_WORK* wk )
{
	enum
	{
		TP_HIT_CIRCLE_R = 16,
		EXIT_IDX = COURSE_ID_MAX, ///< もどるボタンは COURSE_ID の末尾につくのでMAXの値と等しくなる
	};

	CURSOR_WORK* cwk = &wk->wk_cur;
	s8 pre_pos_idx = cwk->pos_idx;
	BOOL retval = FALSE;

	// キャンセルボタンでどこでも終了
	if( sys.trg & PAD_BUTTON_CANCEL )
	{
		return TRUE;
	}

	// ----- 入力処理 -----
	// -- タッチ操作
	if( sys.tp_trg )
	{
		static const RECT_HIT_TBL rect_data[] = {
			{ TP_USE_CIRCLE, OBJPOS_MEDAL_SPEED_X,		OBJPOS_MEDAL_SPEED_Y,	TP_HIT_CIRCLE_R },
			{ TP_USE_CIRCLE, OBJPOS_MEDAL_POWER_X,		OBJPOS_MEDAL_POWER_Y,	TP_HIT_CIRCLE_R },
			{ TP_USE_CIRCLE, OBJPOS_MEDAL_TOCHNIC_X,	OBJPOS_MEDAL_TOCHNIC_Y,	TP_HIT_CIRCLE_R },
			{ TP_USE_CIRCLE, OBJPOS_MEDAL_STAMINA_X,	OBJPOS_MEDAL_STAMINA_Y,	TP_HIT_CIRCLE_R },
			{ TP_USE_CIRCLE, OBJPOS_MEDAL_JUMP_X,		OBJPOS_MEDAL_JUMP_Y,	TP_HIT_CIRCLE_R },
			{ POS_EXIT_Y-2*8, POS_EXIT_Y+2*8, POS_EXIT_X-4*8, POS_EXIT_X+4*8 },	///< もどるボタン
			{ TP_HIT_END, 0, 0, 0 },
		};

		int result;

		result = GF_TP_HitTrg( rect_data );
//		HOSAKA_PRINT("result:%d dat{%d,%d}, tp{%d,%d}\n",result, rect_data[result].circle.x, rect_data[result].circle.y, sys.tp_x, sys.tp_y );

		if( result != RECT_HIT_NONE )
		{
			if( result == EXIT_IDX )
			{
				HOSAKA_PRINT( "touch exit \n" );
				retval = TRUE;
			}
			else // if( cwk->pos_idx != result )
			{
				cwk->b_move_to_right = ( cwk->pos_idx < result ); // 前回のIDと今回のIDを比較してメダルの出現方向を決定

				CATS_ObjectAnimeSeqSetCap( wk->cap[ OBJ_ID_MEDAL_CURSOR ], NANR_obj_trophy_cur_tp );
				CATS_ObjectAutoAnimeSetCap( wk->cap[ OBJ_ID_MEDAL_CURSOR ], TRUE );

				Snd_SePlay( SEQ_SE_DP_SELECT ); // 移動音
			}

			cwk->pos_idx = result;
		}
	}
	else
	// -- キー操作
	if( (sys.repeat & PAD_KEY_RIGHT) || (sys.repeat & PAD_KEY_DOWN) )
	{
		if( cwk->pos_idx < COURSE_ID_MAX )
		{
			cwk->pos_idx++;
			cwk->b_move_to_right = TRUE;
			Snd_SePlay( SEQ_SE_DP_SELECT ); // 移動音
		}
	}
	else
	if( (sys.repeat & PAD_KEY_LEFT) || (sys.repeat & PAD_KEY_UP) )
	{
		if( cwk->pos_idx > 0 )
		{
			cwk->pos_idx--;
			cwk->b_move_to_right = FALSE;
			Snd_SePlay( SEQ_SE_DP_SELECT ); // 移動音
		}
	}
	else if( (sys.trg & PAD_BUTTON_DECIDE) && cwk->pos_idx == EXIT_IDX )
	{
		return TRUE;	///< カーソルがもどるボタンならAで終了
	}

	cwk->pos_idx = MATH_CLAMP( cwk->pos_idx, 0, COURSE_ID_MAX );
	wk->crs_idx = cwk->pos_idx;

	// ----- 値が変更された ----
	if( pre_pos_idx != cwk->pos_idx )
	{
		// -- 描画処理 --

		// カーソル移動
		CATS_ObjectPosSetCap( wk->cap[ OBJ_ID_MEDAL_CURSOR ],
				c_medal_pos_tbl[ cwk->pos_idx ][0],
				c_medal_pos_tbl[ cwk->pos_idx ][1] );

		if( cwk->pos_idx == EXIT_IDX )
		{
			CATS_ObjectAnimeSeqSetCap( wk->cap[ OBJ_ID_MEDAL_CURSOR ], NANR_obj_trophy_cur_btn );
		}
		else
		{
			// タッチされていなければ直ちにカーソルを基本形に
			if( CATS_ObjectAnimeSeqGetCap( wk->cap[ OBJ_ID_MEDAL_CURSOR ] ) != NANR_obj_trophy_cur_tp )
			{
				CATS_ObjectAnimeSeqSetCap( wk->cap[ OBJ_ID_MEDAL_CURSOR ], NANR_obj_trophy_cur );
			}

			// EXIT → 一個前の要素 の時は項目の内容が一緒なので更新しない
			if( !(pre_pos_idx == EXIT_IDX && cwk->pos_idx == EXIT_IDX-1) )
			{
				OBJ_Enable( wk, FALSE );
				wk->b_gph_flash = TRUE;	// OBJ更新フラグON
			}
		}
	}

	return retval;
}
